package com.project.util;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class DaoFactory {
    private static Properties pro = new Properties();
    static{
        try {
            pro.load(new FileReader("config/dao.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Object  getDao(String daoInterName){
        //根据键得到值
        String value =  pro.getProperty(daoInterName);

        try {
            Class c= Class.forName(value);
            //调用无参构造方法，产生该类的对象
            return c.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
